package com.ygo.feihua;

import android.os.Bundle;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;

public class NewZtliebiao extends AppCompatActivity
{
	EditText zt_lb;
	Button zt_qd;
	Gongju gj;
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		// TODO: Implement this method
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ztliebiao);
		gj=Gongju.getdx(this);
		zt_lb=(EditText) findViewById(R.id.zt_lb);
	
		gj.cshToolbar((Toolbar) findViewById(R.id.toolbar),"战队提示列表");	
		
		final File f=new File(Environment.getExternalStorageDirectory().toString()+"/ygo助手/战队列表.txt");
		String aa="";
		try{
			BufferedReader reader=new BufferedReader(new InputStreamReader(new FileInputStream(f)));
			String line="";

			for (;(line = reader.readLine()) != null;)
			{
				aa += line +"\n";
			}
		}
		catch (IOException e)
		{}
		zt_lb.setText(aa);
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu)
	{
		// TODO: Implement this method
		getMenuInflater().inflate(R.menu.menu_qd, menu);
		return super.onCreateOptionsMenu(menu);
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item)
	{
		// TODO: Implement this method
		switch(item.getItemId()){
			case R.id.action_qd:
				try
				{
					
					FileOutputStream fos=new FileOutputStream(new File(gj.PATH_GEN+"ygo助手/TeamList.txt"));
					String ss=zt_lb.getText().toString().trim();
					if(!ss.equals("")){
					fos.write(ss.getBytes());
					fos.close();
					}else{
						Gongju.copyAssets("TeamList.txt",Gongju.PATH_OURYGO);
					}
					gj.show("设置成功");
					finish();
				}
				catch (IOException e)
				{
					gj.show("设置失败,原因为"+e);
				}
			
				break;
		}
		
		
		return super.onOptionsItemSelected(item);
	}
	
	
	
}
